package com.example.microserviceuserservice.Controller;

import com.example.microserviceuserservice.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserController {
    @Autowired
    RestTemplate restTemplate;

    @GetMapping(value = "/getOrderById/{id}")
    public List<Order> getOrderById(@PathVariable int id){
        return this.restTemplate.getForObject("http://microservice-eureka-order/getOrderById/" + id, ArrayList.class);
    }

    @GetMapping(value = "/getOrderByUserName/{userName}")
    public List<Order>  getOrderByUserName(@PathVariable String userName){
        return this.restTemplate.getForObject("http://microservice-eureka-order/getOrderByUserName/" + userName, ArrayList.class);
    }
}
